package com.example.supermarket.controller;

import com.example.supermarket.service.PriceCalculatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 购物控制器，提供REST API接口
 */
@RestController
@RequestMapping("/api/shopping")
public class ShoppingController {
    
    private final PriceCalculatorService priceCalculatorService;
    
    @Autowired
    public ShoppingController(PriceCalculatorService priceCalculatorService) {
        this.priceCalculatorService = priceCalculatorService;
    }
    
    /**
     * 计算顾客A的购物总价
     * @param appleQuantity 苹果购买数量（斤）
     * @param strawberryQuantity 草莓购买数量（斤）
     * @return 总价
     */
    @GetMapping("/customer-a/price")
    public BigDecimal calculatePriceForCustomerA(
            @RequestParam(defaultValue = "0") int appleQuantity,
            @RequestParam(defaultValue = "0") int strawberryQuantity) {
        return priceCalculatorService.calculatePriceForCustomerA(appleQuantity, strawberryQuantity);
    }
    
    /**
     * 计算顾客B的购物总价
     * @param appleQuantity 苹果购买数量（斤）
     * @param strawberryQuantity 草莓购买数量（斤）
     * @param mangoQuantity 芒果购买数量（斤）
     * @return 总价
     */
    @GetMapping("/customer-b/price")
    public BigDecimal calculatePriceForCustomerB(
            @RequestParam(defaultValue = "0") int appleQuantity,
            @RequestParam(defaultValue = "0") int strawberryQuantity,
            @RequestParam(defaultValue = "0") int mangoQuantity) {
        return priceCalculatorService.calculatePriceForCustomerB(appleQuantity, strawberryQuantity, mangoQuantity);
    }
    
    /**
     * 计算顾客C的购物总价
     * @param appleQuantity 苹果购买数量（斤）
     * @param strawberryQuantity 草莓购买数量（斤）
     * @param mangoQuantity 芒果购买数量（斤）
     * @return 总价
     */
    @GetMapping("/customer-c/price")
    public BigDecimal calculatePriceForCustomerC(
            @RequestParam(defaultValue = "0") int appleQuantity,
            @RequestParam(defaultValue = "0") int strawberryQuantity,
            @RequestParam(defaultValue = "0") int mangoQuantity) {
        return priceCalculatorService.calculatePriceForCustomerC(appleQuantity, strawberryQuantity, mangoQuantity);
    }
    
    /**
     * 计算顾客D的购物总价
     * @param appleQuantity 苹果购买数量（斤）
     * @param strawberryQuantity 草莓购买数量（斤）
     * @param mangoQuantity 芒果购买数量（斤）
     * @return 总价
     */
    @GetMapping("/customer-d/price")
    public BigDecimal calculatePriceForCustomerD(
            @RequestParam(defaultValue = "0") int appleQuantity,
            @RequestParam(defaultValue = "0") int strawberryQuantity,
            @RequestParam(defaultValue = "0") int mangoQuantity) {
        return priceCalculatorService.calculatePriceForCustomerD(appleQuantity, strawberryQuantity, mangoQuantity);
    }
}